package com.quotes.indicators;

import java.util.Date;
import com.quotes.datamodell.*;

public class MomentumIndicator
{
	private TimeSeries momentum = null;
	
	public MomentumIndicator(Quotes quotes, int ticks) {
		momentum = calculateMomentum(quotes.getQuote(QuotesType.CLOSE), ticks);
	}
	
	public TimeSeries getMomentum() {
		return momentum;
	}
	
	public static TimeSeries calculateMomentum(TimeSeries input, int ticks) {
		TimeSeries result = new TimeSeries();
		double[] data = input.ValuesAsArray();
		Date[] keys = input.DatesAsArray();
		
		for (int i=ticks; i<data.length; i++) {
			double value = 0;
			int comparePos = i - ticks;

			if (comparePos >= 0)
				value = input.getOr0(keys[i]) - input.getOr0(keys[comparePos]);
			
			result.put(keys[i], value);
		}
		
		return result;
	}
}
